package gdut.imis.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import gdut.imis.Utils.Result;
import gdut.imis.domain.Matches;
import gdut.imis.enums.Status;
import gdut.imis.mapper.MatchesMapper;
import gdut.imis.service.MatchesService;
import gdut.imis.vo.MatchesVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description
 * @Author JiaFu
 * @Date 2023/4/8 18:36
 */
@Service
@RequiredArgsConstructor
public class MatchesServiceImpl extends ServiceImpl<MatchesMapper, Matches> implements MatchesService {
    private final MatchesMapper matchesMapper;

    /***
     * 新增比赛档案
     * @param: matches
     * @return Result
     */
    @Override
    public Result addMatches(Matches matches) {
        if (Objects.isNull(matches)) {
            return Result.errorWithArgs(Status.REQUEST_PARAMS_NOT_VALID_ERROR, "matches");
        }
        boolean flag = this.save(matches);
        if (flag) {
            return Result.success();
        }
        return Result.errorWithArgs(Status.FAILED, "新增比赛档案失败");
    }


    /***
     * 根据学生id查询学生第一次参加比赛的档案回忆录
     * @param: studentId
     * @return Result
     */
    @Override
    public Result getMatchesMemoryByStuId(Long studentId) {
        MatchesVo matchesVo = matchesMapper.getMatchesMemoryByStuId(studentId);
        if (Objects.isNull(matchesVo)) {
            return Result.errorWithArgs(Status.FAILED,"没有查询到学生第一次参加比赛的档案回忆录");
        }
        return Result.success(matchesVo);
    }
}
